#import "KFCateCell.h"

@interface KFCateCell()
@property(nonatomic, strong) UILabel *nameLab;
@property(nonatomic, strong) UIView *indicatorView; // 添加指示器视图
@end

@implementation KFCateCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = UIColor.whiteColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createCusUI];
    }
    return self;
}

- (void)createCusUI {
    // 添加指示器视图（左侧高亮条）
    self.indicatorView = [[UIView alloc] init];
    self.indicatorView.backgroundColor = [UIColor redColor]; // 高亮颜色
    self.indicatorView.hidden = YES; // 默认隐藏
    [self.contentView addSubview:self.indicatorView];
    
    self.nameLab = [UILabel labelWithTitle:@"" color:UIColor.blackColor fontSize:14];
    [self.contentView addSubview:self.nameLab];
    
    // 布局
    self.indicatorView.sd_layout
    .leftEqualToView(self.contentView)
    .topEqualToView(self.contentView)
    .bottomEqualToView(self.contentView)
    .widthIs(4); // 宽度4像素
    
    self.nameLab.sd_layout
    .centerXEqualToView(self.contentView)
    .centerYEqualToView(self.contentView)
    .heightIs(20);
    [self.nameLab setSingleLineAutoResizeWithMaxWidth:300];
    UIView * line = [UIView new];
    line.backgroundColor =[UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
    [self.contentView addSubview:line];
    line.sd_layout.leftEqualToView(self.contentView).rightEqualToView(self.contentView).bottomEqualToView(self.contentView).heightIs(1);
}

- (void)setModel:(KFCategoryModel *)model {
    self.nameLab.text = model.categoryName;
}

// 设置选中状态
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // 更新UI状态
    if (selected) {
        self.contentView.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0];
        self.nameLab.textColor = [UIColor redColor]; // 选中文字颜色
        self.indicatorView.hidden = NO; // 显示指示器
    } else {
        self.contentView.backgroundColor = UIColor.whiteColor;
        self.nameLab.textColor = UIColor.blackColor; // 默认文字颜色
        self.indicatorView.hidden = YES; // 隐藏指示器
    }
}

@end
